package com.mts.indicatorserver.dictinfo.controller

import com.mts.indicatorcommon.dictinfo.vo.DictInfoVo
import com.mts.indicatorcommon.dictinfo.search.DictInfoSearch
import com.mts.indicatorserver.dictinfo.service.DictInfoService
import com.mts.javacommon.jpabase.ResultVoUtil
import com.mts.javacommon.jpabase.ResultVo
import com.mts.javacommon.jpabase.PageVo
import com.mts.javacommon.jpabase.PageUtil
import org.springframework.data.domain.Page
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
import io.swagger.v3.oas.annotations.tags.Tag
import org.slf4j.LoggerFactory
import org.springframework.web.bind.annotation.*
import jakarta.validation.Valid


/**
 * <pre>
 *      字典信息表 前端控制器
 * </pre>
 *
 * @author Johnny
 * @date 2025-08-22
 */
@Tag(name = "字典信息表")
@RestController
@RequestMapping("/api/dictInfo")
class DictInfoController(
    private val dictInfoService: DictInfoService
) {

    /**
     * 带条件查询的 分页接口
     */
    @GetMapping("/listByCondition")
    @Operation(summary = "根据条件查询字典信息表 (分页)")
    fun listByCondition(
        @Parameter(description = "查询条件") dictInfoSearch: DictInfoSearch,

        @Parameter(description = "分页条件") pageVo: PageVo
    ): ResultVo<Page<DictInfoVo>> {
        val page = dictInfoService.listByCondition(
            dictInfoSearch, PageUtil.initPage(pageVo)
        )
        return ResultVoUtil.success(page)
    }

    @PostMapping("/add")
    @Operation(summary = "新增字典信息表信息")
    fun add(
        @RequestBody @Valid @Parameter(description = "新增的数据") dictInfoVo: DictInfoVo
    ): ResultVo<Void> {
        dictInfoService.add(dictInfoVo)
        return ResultVoUtil.success()
    }

    @PostMapping("/edit")
    @Operation(summary = "修改字典信息表信息")
    fun edit(
        @RequestBody @Valid @Parameter(description = "修改的数据") dictInfoVo: DictInfoVo
    ): ResultVo<Void> {
        dictInfoService.edit(dictInfoVo)
        return ResultVoUtil.success()
    }

    @GetMapping("/delete/{id}")
    @Operation(summary = "删除字典信息表信息")
    fun delete(
        @Parameter(description = "字典信息表id", example = "1") @PathVariable id: Long
    ): ResultVo<Void> {
        dictInfoService.delete(id)
        return ResultVoUtil.success()
    }

    @PostMapping("/deletes")
    @Operation(summary = "批量删除字典信息表信息")
    fun deletes(
        @RequestBody @Parameter(description = "要删除的id列表") ids: Array<Long>
    ): ResultVo<Void> {
        val idList = ids.toList()
        dictInfoService.deletes(idList)
        return ResultVoUtil.success()
    }
}
